package com.orange.common.autoconfig.properties;

import cn.hutool.core.bean.BeanUtil;
import com.easemob.im.server.EMProperties;
import com.easemob.im.server.EMService;
import io.netty.util.internal.StringUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Description: 环信配置文件
 */
@ConfigurationProperties(prefix = "orange.autoconfig.im")
@Component
@Data
@Slf4j
public class IMProperties {
    private String appkey;
    private String clientId;
    private String clientSecret;

    @Bean
    public EMService emService() {
       if(StringUtil.isNullOrEmpty(appkey)||
               StringUtil.isNullOrEmpty(clientId)||
               StringUtil.isNullOrEmpty(clientSecret)){
           log.info("环信配置文件未配置");
           return null;
       }
        EMProperties emProperties = EMProperties.builder()
                .setAppkey(this.getAppkey())
                .setClientId(this.getClientId())
                .setClientSecret(this.getClientSecret())
                .build();
        return new EMService(emProperties);
    }
}
